/*
 * @Author: 系统
 * @Description: 床位管理Mock数据（遵循 ward.js 风格）
 * @Date: 2025-11-12 14:00:00
 */

// 床位与患者模拟数据
const bedList = [
  {
    id: 1,
    bedNo: '001',
    wardName: '一病区',
    status: 'occupied', // occupied-已占用 empty-空床
    patient: {
      id: 101,
      name: '张三',
      sex: 1,
      age: 28,
      diagnosis: '急性阑尾炎伴发热，建议手术治疗，术后持续观察',
      doctor: '李主任',
      nurse: '王护士',
      admissionTime: '1'
    }
  },
  {
    id: 2,
    bedNo: '002',
    wardName: '一病区',
    status: 'occupied',
    patient: {
      id: 102,
      name: '李四',
      sex: 2,
      age: 35,
      diagnosis: '肺部感染，使用广谱抗生素治疗并吸氧支持',
      doctor: '赵医生',
      nurse: '刘护士',
      admissionTime: '21'
    }
  },
  { id: 3, bedNo: '003', wardName: '一病区', status: 'empty', patient: null },
  { id: 4, bedNo: '004', wardName: '一病区', status: 'empty', patient: null },
  {
    id: 5,
    bedNo: '005',
    wardName: '二病区',
    status: 'occupied',
    patient: {
      id: 103,
      name: '王五',
      sex: 1,
      age: 42,
      diagnosis: '糖尿病并发症控制，持续胰岛素治疗',
      doctor: '周医生',
      nurse: '宋护士',
      admissionTime: '23'
    }
  },
  { id: 6, bedNo: '006', wardName: '二病区', status: 'empty', patient: null },
  {
    id: 7,
    bedNo: '007',
    wardName: '二病区',
    status: 'occupied',
    patient: {
      id: 104,
      name: '赵六',
      sex: 2,
      age: 31,
      diagnosis: '骨折术后康复，每日物理治疗',
      doctor: '钱医生',
      nurse: '邹护士',
      admissionTime: '34'
    }
  },
  { id: 8, bedNo: '008', wardName: '二病区', status: 'empty', patient: null },
  {
    id: 9,
    bedNo: '009',
    wardName: '三病区',
    status: 'occupied',
    patient: {
      id: 105,
      name: '钱七',
      sex: 1,
      age: 63,
      diagnosis: '慢性心衰加重，需严密监护与药物调整',
      doctor: '孙医生',
      nurse: '吴护士',
      admissionTime: '87'
    }
  },
  { id: 10, bedNo: '010', wardName: '三病区', status: 'empty', patient: null },
  {
    id: 11,
    bedNo: '011',
    wardName: '三病区',
    status: 'occupied',
    patient: {
      id: 106,
      name: '孙八',
      sex: 2,
      age: 22,
      diagnosis: '急诊入院，疑似阑尾炎，等待进一步检查',
      doctor: '李主任',
      nurse: '王护士',
      admissionTime: '88'
    }
  },
  { id: 12, bedNo: '012', wardName: '三病区', status: 'empty', patient: null }
]

// 医生与护士列表
const doctorList = [
  { id: 1, name: '李主任' },
  { id: 2, name: '赵医生' },
  { id: 3, name: '周医生' },
  { id: 4, name: '钱医生' },
  { id: 5, name: '孙医生' }
]
const nurseList = [
  { id: 1, name: '王护士' },
  { id: 2, name: '刘护士' },
  { id: 3, name: '宋护士' },
  { id: 4, name: '邹护士' },
  { id: 5, name: '吴护士' }
]

// 待分配床位患者（入院但未分配床位）
const pendingAssignList = [
  { id: 201, name: '胡九', sex: 1, dept: '普外科', admissionTime: '2025-11-12 08:20' },
  { id: 202, name: '魏十', sex: 2, dept: '呼吸内科', admissionTime: '2025-11-12 09:05' },
  { id: 203, name: '蒋十一', sex: 1, dept: '骨科', admissionTime: '2025-11-12 10:40' }
]

// 待办统计
const todoStats = {
  pendingAssign: pendingAssignList.length, // 待分配床位
  arrears: 3, // 已欠费
  dischargeTransfer: 2, // 出院/转科
  orderVerify: 5, // 医嘱待核对
  orderExecute: 4, // 医嘱待执行
  orderStopRevoke: 1 // 医嘱停止/撤销
}

// Mock API
export const mockBedApi = {
  // 获取床位卡片（支持状态与筛选）
  getBedsList: (params = {}) => {
    const { status = 'all', keyword = '', doctors = [], nurses = [] } = params

    let list = [...bedList]

    // 状态筛选
    if (status !== 'all') {
      if (status === 'empty') {
        list = list.filter(item => item.status === 'empty')
      } else {
        // 其他状态均为occupied患者的不同标签，这里用简单示例映射
        list = list.filter(item => item.status === 'occupied')
      }
    }

    // 关键字筛选（患者姓名模糊）
    if (keyword) {
      const kw = keyword.trim()
      list = list.filter(
        item =>
          item.patient &&
          (item.patient.name.includes(kw) || (item.patient.diagnosis && item.patient.diagnosis.includes(kw)))
      )
    }

    // 医生多选筛选
    if (Array.isArray(doctors) && doctors.length) {
      list = list.filter(item => item.patient && doctors.includes(item.patient.doctor))
    }

    // 护士多选筛选
    if (Array.isArray(nurses) && nurses.length) {
      list = list.filter(item => item.patient && nurses.includes(item.patient.nurse))
    }

    return {
      code: 200,
      message: '获取成功',
      data: list
    }
  },

  // 获取待办统计
  getTodoStats: () => ({ code: 200, message: '获取成功', data: todoStats }),

  // 获取待分配列表
  getPendingAssignList: () => ({ code: 200, message: '获取成功', data: pendingAssignList }),

  // 获取医生列表
  getDoctorList: () => ({ code: 200, message: '获取成功', data: doctorList }),

  // 获取护士列表
  getNurseList: () => ({ code: 200, message: '获取成功', data: nurseList }),

  // 根据岗位编码获取用户列表（doctor/nurse）
  // 关键节点：满足页面对数据源 listUserByPostCode 的依赖
  listUserByPostCode: postCode => {
    const code = String(postCode || '').toLowerCase()
    if (code === 'doctor') return { code: 200, message: '获取成功', data: doctorList }
    if (code === 'nurse') return { code: 200, message: '获取成功', data: nurseList }
    return { code: 200, message: '获取成功', data: [] }
  }
}

export default mockBedApi
